package com.zeroext.show.action;

import net.sf.json.JSONObject;

import com.zeroext.action.common.BaseAction;
import com.zeroext.common.util.JsonWapper;
import com.zeroext.dao.common.SimplePage;
import com.zeroext.show.entity.Book;
import com.zeroext.show.service.BookService;
import com.zeroext.sys.util.DateUtil;
/**
 * Book Action
 * @author ouch
 *
 */
@SuppressWarnings("serial")
public class BookAction extends BaseAction {
    private int pageSize = 10;
    private int start = 0;
    
    private BookService bookService;
    
    @SuppressWarnings("static-access")
    public String listBook()throws Exception{
        SimplePage<Book> pages = bookService.listBooks(start, pageSize);
        JsonWapper jw = new JsonWapper();
        for(Book book : pages.getData()){
            JSONObject jo = jw.nextItem();
            jo.put("id", book.getId());
            jo.put("name", book.getName());
            jo.put("publisher", book.getPublisher());
            jo.put("author", book.getAuthor());
            jo.put("createDate", DateUtil.getYYMMDDHHMMSS(book.getCreateDate()));
            jo.put("remain", book.getRemain());
            jw.endItem(jo);
        }
        jw.writeStore(this.getResponse(), pages.getTotal());
        return null;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public BookService getBookService() {
        return bookService;
    }

    public void setBookService(BookService bookService) {
        this.bookService = bookService;
    }
    
    
}
